package org.jiangy.authentication.config;

import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

/**
 * Jackson 序列化工具配置：
 * 1. 忽略在 JSON 字符串中存在的属性，而在 Java Bean 中不存在的属性。
 * <p>创建时间: 2023/2/26 </p>
 *
 * @author <a href="mailto:jiangliu0316@dingtalk.com" rel="nofollow">蒋勇</a>
 */
@Configuration
public class JacksonConfig implements Jackson2ObjectMapperBuilderCustomizer, Ordered {
    /**
     * Customize the JacksonObjectMapperBuilder.
     *
     * @param builder the JacksonObjectMapperBuilder to customize
     */
    @Override
    public void customize(Jackson2ObjectMapperBuilder builder) {
        // 2. 忽略反序列化时在 JSON 字符串存，但在 Java Bean 中不存在的属性
        builder
                .failOnUnknownProperties(false);
    }

    /**
     * Get the order value of this object.
     * <p>Higher values are interpreted as lower priority. As a consequence,
     * the object with the lowest value has the highest priority (somewhat
     * analogous to Servlet {@code load-on-startup} values).
     * <p>Same order values will result in arbitrary sort positions for the
     * affected objects.
     *
     * @return the order value
     * @see #HIGHEST_PRECEDENCE
     * @see #LOWEST_PRECEDENCE
     */
    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE;
    }
}
